package com.bw.lyc.mvp.view.mine.adapter;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bw.lyc.R;
import com.bw.lyc.mvp.model.entity.UserItemEntity;
import com.bw.lyc.mvp.view.mine.SettingActivity;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import org.jetbrains.annotations.NotNull;

public class UserAdapter extends BaseQuickAdapter<UserItemEntity, BaseViewHolder> {
    public UserAdapter() {
        super(R.layout.item_mine_itemes);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, UserItemEntity userItemEntity) {
        baseViewHolder.setText(R.id.mine_itemes_tv,userItemEntity.name);
        baseViewHolder.setImageResource(R.id.mine_itemes_arrow_img,R.mipmap.icon_pn_arrows);

        ImageView mine_itemes_arrow_img = baseViewHolder.itemView.findViewById(R.id.mine_itemes_arrow_img);
        TextView mine_itemes_tv = baseViewHolder.itemView.findViewById(R.id.mine_itemes_tv);
        mine_itemes_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (userItemEntity.name.equals("更多设置")) {
                    Intent intent = new Intent(getContext(), SettingActivity.class);
                    getContext().startActivity(intent);
                }
            }
        });
        mine_itemes_arrow_img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                userItemEntity.selFlag = !userItemEntity.selFlag;
                if (userItemEntity.name.equals("夜间模式")) {
                    if (userItemEntity.selFlag) {
                        baseViewHolder.setImageResource(R.id.mine_itemes_arrow_img,R.mipmap.new_on);
                    } else {

                        baseViewHolder.setImageResource(R.id.mine_itemes_arrow_img,R.mipmap.new_off);
                    }
                }
                if (userItemEntity.name.equals("更多设置")) {
                    Intent intent = new Intent(getContext(), SettingActivity.class);
                    getContext().startActivity(intent);
                }
            }
        });


        if (userItemEntity.name.equals("夜间模式")) {
            if (userItemEntity.selFlag) {
                baseViewHolder.setImageResource(R.id.mine_itemes_arrow_img,R.mipmap.new_on);
            } else {
                baseViewHolder.setImageResource(R.id.mine_itemes_arrow_img,R.mipmap.new_off);
            }
        }
        

    }
}
